package com.client.buttlefield.ui;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javafx.animation.Interpolator;
import javafx.animation.PathTransition;
import javafx.animation.Animation.Status;
import javafx.event.EventType;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.util.Duration;

class Participant extends Circle{
	
	double currentX;
	double currentY;
	
	Byte ident;
	
	Boolean isActive = false;
	/***
	 * begin properties of this class
	 */
	
	protected void changeActive(){
		isActive = true;
	}
	
 	protected void setIdent(Byte id) {
		this.ident = id;
	}
	
	protected Byte getIdent() {
		return ident;
	}
	/***
	 * end properties of this class
	 */
	
	PathTransition pathTransition;
	
	public Participant(double x, double y, Color color) {
		super(x, y, 30);
		
		currentX = x; 
		currentY = y;
		
		setFill(color);
		
		pathTransition = new PathTransition();
		pathTransition.setNode(this);
		pathTransition.setInterpolator(Interpolator.LINEAR);
	}
	
	void moving(double x, double y, int n){
		Path path = new Path();
        path.getElements().add(new MoveTo(currentX, currentY));
        path.getElements().add(new LineTo(x, y));

        pathTransition.setDuration(new Duration(100*n));
        pathTransition.setPath(path);
        pathTransition.play();
	}
	
	void stopMoving(double x, double y){
		if(pathTransition.getStatus() == Status.RUNNING){
			pathTransition.stop();
		}
		
		assignLocate(x, y);
	}
	
	public void assignLocate(double x,  double y){
		this.setCenterX(x);
		this.setCenterY(y);
	}
	
	void assign(Boolean active){
		Buttlefield.createButtle().addParticipant(this, active);
	}
}
